<?php 
namespace Home\Model;
use Think\Model;
/*
	ng文章
*/
class ArticleModel extends Model {

	//插入文章
	/*
	 *@param array $data 数据数组
	 */
	public function insert_article($data){
		$result = M('article')->add($data);
		return $result;
	}
	
	//查询文章列表
	/*
	 *@param int $uid   用户id
	 */
	public function article_list($uid,$limit = '0,10',$files='*'){
		$result = M('article')->where('uid = %d and status = 1',$uid)->order('id desc')->limit($limit)->field($files)->select();
		return $result;
	}
	
	//查询文章内容
	/*
	 *@param int $uid 用户id
	 *@param int $aid 文章id
	 */
	public function article_detail($aid,$status = '0'){
		$result = M('article')->where('id = %d and status = %d',$aid,$status)->find();
		return $result;
	}
	
	//更新文章内容
	/*
	 *@param int $uid 用户id
	 *@param int $aid 文章id
	 *@param array $data 数据
	 */
	public function update_detail($uid,$aid,$data){
		$result = M('article')->where('uid =  %d and id = %d',$uid,$aid)->save($data);
		return $result;
	}
	
	//删除文章
	/*
	 *@param int $uid 用户id
	 *@param int $aid 文章id
	 */
	public function delete_detail($uid,$aid){
		$result = M('article')->where('uid = %d and id = %d',$uid,$aid)->delete();
		return $result;
	}
	
	//查询文章列表（站内）
	public function article_list_all($limit= '0,10',$field="*",$cat_id = 0){
		
		//如果分类为0
		if(empty($cat_id)){
			
			$result = M('article_site')->where('status = 1')->field($field)->order('taxis desc,id desc')->limit($limit)->select();
			
		}else{
			$where = ' and cat_id = '.$cat_id.'';
			$result = M('article_site')
				->where('status = 1'.$where.'')
				->field($field)
				->order('taxis desc,id desc')->limit($limit)
				->select();
		}
		
		
		return $result;
	}
	
	//查询站内文章内容
	public function article_detail_inside($aid){
		$result = M('article_site')->where('status = 1 and id = %d',$aid)->find();
		return $result;
	}
	
	/**
	 * //插入md5图片
	 * $date = array(
	 *	  'img_name'.
	 *    'upload_time',
	 *    'picture_address',
	 *    'key',
	 *    'user_id',
	 *    'is_article'
	 * );
	 * @param  array    $date 数组
	 * @return int/bool 
	 * 
	 */
	public function  picture_attachments($date){
		$result = M('HomePictureAttachment')->add($date);
		return $result;
	}
		
		
	/**
	 * 插入文章记录表
	 * @param  array $date 
	 * @return int/bool  
	 *
	 */ 
	 
	 public function insert_content_log($date){
		 $result = M('ContentLog')->add($date);
		 return $result; 
	 }
	 
}
